//
//  QShowSignBoxView.m
//  QoilPublic
//
//  Created by 杨凯 on 2017/3/20.
//  Copyright © 2017年 杨凯. All rights reserved.
//

#import "QShowSignBoxView.h"
#import "QShowSignView.h"
#import "QPointsVC.h"
@implementation QShowSignBoxView{
    UIControl *_maskView;
    QShowSignView *_signView;

}
#pragma mark ---签到
- (instancetype)initWithTitle:(NSString *)title{
    self = [super init];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        self.frame = [UIScreen mainScreen].bounds;
        [self configViewWithTitle:title];
    }
    return self;
}
- (void)configViewWithTitle:(NSString *)title{
    _maskView = [[UIControl alloc] initWithFrame:[UIScreen mainScreen].bounds];
    _maskView.backgroundColor = [UIColor colorWithWhite:0.1 alpha:0.5];
    _maskView.hidden = YES;
    [self addSubview:_maskView];
    
    _signView = [[[NSBundle mainBundle] loadNibNamed:@"QShowSignView" owner:self options:nil] lastObject];
    _signView.frame = CGRectMake((kScreenWidth - 225)/2, kScreenHeight, 225, 310);
    __block QShowSignBoxView *weakSelf = self;
    _signView.CloseBlock=^(){
        [weakSelf hidePlayBoxView1];
    };
    
    [_maskView addSubview:_signView];
    _signView.str = title;
}



- (void)showPlayBoxView{
    
    UIWindow *window = [[UIApplication sharedApplication].delegate window];
    
    [window addSubview:_maskView];
    _maskView.hidden = NO;
    _maskView.alpha = 0;
    [UIView animateWithDuration:0.5 delay:0 usingSpringWithDamping:0.6 initialSpringVelocity:1 options:UIViewAnimationOptionCurveLinear animations:^{
        _signView.center = self.center;
        _maskView.alpha = 1;
    } completion:^(BOOL finished) {
        
    }];
}

- (void)hidePlayBoxView1{
    [[NSNotificationCenter defaultCenter] postNotificationName:kNotificationPointSignSuccess object:nil];
    _maskView.alpha = 1;
    [UIView animateWithDuration:.3 animations:^{
        //_signView.frame = CGRectMake((kScreenWidth-255)/2, kScreenHeight, 255, 310);
        _maskView.alpha = 0;
    } completion:^(BOOL finished) {
        _maskView.hidden = YES;
        [_maskView removeFromSuperview];
        [_signView removeFromSuperview];
        [self removeFromSuperview];
    }];
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
